package com.wangbo.kx;

import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.client.RestTemplate;

public class KXUtil {

    /**
     * 输入账户名获取token
     */
    public static JSONObject getValidateCode(RestTemplate restTemplate, String account) {
        String url = "http://50.88.11.215:8080/JQ/getValidatecode";

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("account", account);

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<JSONObject> httpEntity = new HttpEntity<>(jsonObject, headers);

        JSONObject result = restTemplate.postForObject(url, httpEntity, JSONObject.class);
        System.out.printf("科信获取token结果: %s%n", result.toString());
        return result;
    }

    /**
     * 输入身份证号，返回在全省苏康码红黄码数据中是否有命中数据
     */
    public static JSONObject judgeRedYellowCode(RestTemplate restTemplate, String token, String personalIdNo) {
        String url = "http:// 50.88.11.206:38080 /healthcode/judgeRedYellowCode";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("gmsfbs", personalIdNo);

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        headers.add("token", token);
        HttpEntity<JSONObject> httpEntity = new HttpEntity<>(jsonObject, headers);

        JSONObject result = restTemplate.postForObject(url, httpEntity, JSONObject.class);
        System.out.printf("科信苏康码红黄码命中结果: %s%n", result.toString());
        return result;
    }
}
